package edu.gyc.game;

import java.util.*;

public class    hi {
    public static void main(String[] args) {


    }

    public static void placeShip(List<Ship> ships) {
        Set<String> zbSet = new HashSet<>();
        Random random = new Random();
        for (int i = 0; i < 3; i++) {
            int direction = random.nextInt(2);
            int  rowMid=random.nextInt(5)+1;
            int  colMid=random.nextInt(5)+1;
            if (direction == 1) {
                String top=""+(rowMid-1)+colMid;
                String mid=""+(rowMid-0)+colMid;
                String bot=""+(rowMid+1)+colMid;
                if (zbSet.addAll(Arrays.asList(top, mid, bot))) {
                    ArrayList<String> list = new ArrayList<>();
                    list.addAll(Arrays.asList(top, mid, bot));
                    ships.get(i).setLocations(list);
                }else {
                    i--;
                }
            }else {
                String left = "" + rowMid + (colMid - 1);
                String mid = "" + rowMid + (colMid - 0);
                String right = "" + rowMid + (colMid + 1);
                if (zbSet.addAll(Arrays.asList(left, mid, right))) {
                    ArrayList<String> list = new ArrayList<>();
                    list.addAll(Arrays.asList(left, mid, right));
                    ships.get(i).setLocations(list);
                }else {
                    i--;
                }
            }
        }
        System.out.println(ships);
    }

    private static void mid() {
        StringBuffer buffer1=new StringBuffer();
        StringBuffer buffer2=new StringBuffer();

        for (int i = 0; i < 20; i++) {
            int mid1=(int)(Math.random()*2)+2;
            int mid2=(int)(Math.random()*4)+2;
            buffer1.append(mid1);
            buffer2.append(mid2);
        }
        System.out.println("mid1: "+buffer1);
        System.out.println("mid2: "+buffer2);
    }
}
